package com.meshnetics.gb.type.impl.additional;

import com.meshnetics.gb.type.impl.zcl.AbstractDataType;
import com.meshnetics.gb.type.impl.zcl.AbstractDataValue;
import com.meshnetics.gb.util.ByteBufferManager;

import java.nio.ByteBuffer;

/**
 * Base class for instantiable values.
 *
 * @author Yury Aserchev (yaserchev@meshnetics.com)
 *         Date: 27.08.2008 18:10:42
 */
public abstract class BaseDataValue extends AbstractDataValue {
    public BaseDataValue(final AbstractDataType type) {
        super(type);
    }

    public final byte[] bytesValue() {
        final ByteBuffer buffer = ByteBufferManager.allocateBE(getDataSize());
        serialize(buffer);
        return buffer.array();
    }

    public final Object toObject() {
        throw new IllegalStateException("not realized");
    }

    public final boolean isInvalid() {
        return false;
    }
}
